package logic

import (
	"context"
	"product-management/productrpc/productrpcclient"

	"product-management/api/internal/svc"
	"product-management/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodUpdatesLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodUpdatesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodUpdatesLogic {
	return &GoodUpdatesLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodUpdatesLogic) GoodUpdates(req *types.GoodUpdatesRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	updates, err := l.svcCtx.ProductRpc.GoodUpdates(l.ctx, &productrpcclient.GoodUpdatesRequest{
		Title:   req.Title,
		Details: req.Details,
		Img:     req.Img,
		UserId:  req.UserId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "修改成功",
		Code:    200,
		Data:    updates,
	}, nil

}
